<template>
  <el-dialog title="会员编辑" width="40%" :before-close="dialogClose" :visible.sync="show">
    <el-form ref="form" :model="item" label-width="100px">
        <el-form-item label="会员姓名">
          <el-input v-model="item.username" class="select_input"></el-input>
        </el-form-item>
        <el-form-item label="会员电话">
          <el-input v-model="item.phone" class="select_input"></el-input>
        </el-form-item>
        <el-form-item label="会员生日">
           <el-date-picker
            @change="birthDayChage"
            v-model="item.birthDay"
            type="date"
            placeholder="会员生日" 
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结婚纪念日">
           <el-date-picker
            @change="marryDayChage"
            v-model="item.marryDay"
            type="date"
            placeholder="结婚纪念日" 
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="子女生日">
           <el-date-picker
            @change="sonBirthDayChage"
            v-model="item.sonBirthDay"
            type="date"
            placeholder="子女生日" 
            format="yyyy-MM-dd"
            value-format="yyyy-MM-dd"
            >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="会员等级">
          <el-select v-model="item.lv" placeholder="会员等级">
            <el-option v-for="(item,index) in cate" :key="index" :label="item.name" :value="item.lv"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="客户来源">
          <el-select v-model="item.source" placeholder="客户来源">
            <el-option v-for="(item,index) in sourceArr" :key="index" :label="item" :value="item"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="美容师">
          <el-select v-model="item.user_id" placeholder="美容师">
            <el-option v-for="(item,index) in userArr" :key="item.uid" :label="item.realname" :value="item.uid"></el-option>
          </el-select>
        </el-form-item>
        <div align="center">
          <el-button type="primary" @click="userSubmit">确 定</el-button>
          <el-button @click="dialogClose">取 消</el-button>
        </div>
      </el-form>
    </el-dialog>
</template>
 
<script>
export default {
  name: 'userEdit',
  props:['show','userArr','item'],
  data() {
    return {
        cate:[
          {id:1,name:'A类会员',lv:'A'},
          {id:2,name:'B类会员',lv:'B'},
          {id:3,name:'C类会员',lv:'C'},
          {id:4,name:'D类会员',lv:'D'}
        ],
        sourceArr:['主动进店','大众点评','朋友推荐','地推拓客','小程序','异业联盟','其他']
    }
  },
  created: function() {

  },
  methods: {
    birthDayChage:function(e){
      this.item.birthDay = e
    },
    marryDayChage:function(e){
      this.item.marryDay = e
    },
    sonBirthDayChage:function(e){
      this.item.sonBirthDay = e
    },
    dialogClose:function(){
      this.$emit("func",{'key':'editShow'})
    },
    userSubmit:function(){
      var validate = {
        username:'会员姓名不能为空',
        phone:'会员手机号码必填',
        birthDay:'会员生日不能为空',
        lv:'请选择会员等级',
        source:'请选择客户来源'
      }
      for(var x in validate){
        if(!this.item[x]){
          this.$message.error(validate[x]);
          return false;
          break;
        }
      }
      var that = this
      this.$post('pc/user/save',this.item).then((res) => {
          if(res.code == 1){
            that.$message.success(res.msg);
            that.$emit("func",{'key':'editShow','type':1})
          }else{
            that.$message.error(res.msg);
          }
      })
    }
  }
}
</script>
<style>
</style>